!pip install yfinance==0.2.4
Requirement already satisfied: yfinance==0.2.4 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (0.2.4) Requirement already satisfied: pandas>=1.3.0 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (1.3.5) Requirement already satisfied: numpy>=1.16.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (1.21.6) Requirement already satisfied: requests>=2.26 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (2.29.0) Requirement already satisfied: multitasking>=0.0.7 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (0.0.11) Requirement already satisfied: lxml>=4.9.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (4.9.2) Requirement already satisfied: appdirs>=1.4.4 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (1.4.4) Requirement already satisfied: pytz>=2022.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (2023.3) Requirement already satisfied: frozendict>=2.3.4 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (2.3.8) Requirement already satisfied: cryptography>=3.3.2 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (38.0.2) Requirement already satisfied: beautifulsoup4>=4.11.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (4.11.1) Requirement already satisfied: html5lib>=1.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.2.4) (1.1) Requirement already satisfied: soupsieve>1.2 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from beautifulsoup4>=4.11.1->yfinance==0.2.4) (2.3.2.post1) Requirement already satisfied: cffi>=1.12 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from cryptography>=3.3.2->yfinance==0.2.4) (1.15.1) Requirement already satisfied: six>=1.9 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from html5lib>=1.1->yfinance==0.2.4) (1.16.0) Requirement already satisfied: webencodings in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from html5lib>=1.1->yfinance==0.2.4) (0.5.1) Requirement already satisfied: python-dateutil>=2.7.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas>=1.3.0->yfinance==0.2.4) (2.8.2) Requirement already satisfied: charset-normalizer<4,>=2 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.26->yfinance==0.2.4) (3.1.0) Requirement already satisfied: idna<4,>=2.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.26->yfinance==0.2.4) (3.4) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.26->yfinance==0.2.4) (1.26.15) Requirement already satisfied: certifi>=2017.4.17 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.26->yfinance==0.2.4) (2023.5.7) Requirement already satisfied: pycparser in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from cffi>=1.12->cryptography>=3.3.2->yfinance==0.2.4) (2.21)
!pip install pandas==1.3.3
Collecting pandas==1.3.3
Downloading pandas-1.3.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.3/11.3 MB 80.5 MB/s eta 0:00:0000:0100:01
Requirement already satisfied: numpy>=1.17.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas==1.3.3) (1.21.6)
Requirement already satisfied: python-dateutil>=2.7.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas==1.3.3) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas==1.3.3) (2023.3)
Requirement already satisfied: six>=1.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas==1.3.3) (1.16.0)
Installing collected packages: pandas
Attempting uninstall: pandas
Found existing installation: pandas 1.3.5
Uninstalling pandas-1.3.5:
Successfully uninstalled pandas-1.3.5
Successfully installed pandas-1.3.3
import pandas as pd
import yfinance as yf
tesla = yf.Ticker("TSLA")
tesla_data = pd.DataFrame(tesla.history(period="max"))
tesla_data.head()
| Open | High | Low | Close | Volume | Dividends | Stock Splits | |
|---|---|---|---|---|---|---|---|
| Date | |||||||
| 2010-06-29 00:00:00-04:00 | 1.266667 | 1.666667 | 1.169333 | 1.592667 | 281494500 | 0.0 | 0.0 |
| 2010-06-30 00:00:00-04:00 | 1.719333 | 2.028000 | 1.553333 | 1.588667 | 257806500 | 0.0 | 0.0 |
| 2010-07-01 00:00:00-04:00 | 1.666667 | 1.728000 | 1.351333 | 1.464000 | 123282000 | 0.0 | 0.0 |
| 2010-07-02 00:00:00-04:00 | 1.533333 | 1.540000 | 1.247333 | 1.280000 | 77097000 | 0.0 | 0.0 |
| 2010-07-06 00:00:00-04:00 | 1.333333 | 1.333333 | 1.055333 | 1.074000 | 103003500 | 0.0 | 0.0 |
tesla_data.reset_index(inplace=True)
tesla_data
| Date | Open | High | Low | Close | Volume | Dividends | Stock Splits | |
|---|---|---|---|---|---|---|---|---|
| 0 | 2010-06-29 00:00:00-04:00 | 1.266667 | 1.666667 | 1.169333 | 1.592667 | 281494500 | 0.0 | 0.0 |
| 1 | 2010-06-30 00:00:00-04:00 | 1.719333 | 2.028000 | 1.553333 | 1.588667 | 257806500 | 0.0 | 0.0 |
| 2 | 2010-07-01 00:00:00-04:00 | 1.666667 | 1.728000 | 1.351333 | 1.464000 | 123282000 | 0.0 | 0.0 |
| 3 | 2010-07-02 00:00:00-04:00 | 1.533333 | 1.540000 | 1.247333 | 1.280000 | 77097000 | 0.0 | 0.0 |
| 4 | 2010-07-06 00:00:00-04:00 | 1.333333 | 1.333333 | 1.055333 | 1.074000 | 103003500 | 0.0 | 0.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 3290 | 2023-07-26 00:00:00-04:00 | 263.250000 | 268.040009 | 261.750000 | 264.350006 | 95856200 | 0.0 | 0.0 |
| 3291 | 2023-07-27 00:00:00-04:00 | 268.309998 | 269.130005 | 255.300003 | 255.710007 | 103697300 | 0.0 | 0.0 |
| 3292 | 2023-07-28 00:00:00-04:00 | 259.859985 | 267.250000 | 258.230011 | 266.440002 | 111446000 | 0.0 | 0.0 |
| 3293 | 2023-07-31 00:00:00-04:00 | 267.480011 | 269.079987 | 263.779999 | 267.429993 | 84582200 | 0.0 | 0.0 |
| 3294 | 2023-08-01 00:00:00-04:00 | 266.260010 | 266.470001 | 260.250000 | 261.070007 | 83166000 | 0.0 | 0.0 |
3295 rows × 8 columns
tesla_data.head()
| Date | Open | High | Low | Close | Volume | Dividends | Stock Splits | |
|---|---|---|---|---|---|---|---|---|
| 0 | 2010-06-29 00:00:00-04:00 | 1.266667 | 1.666667 | 1.169333 | 1.592667 | 281494500 | 0.0 | 0.0 |
| 1 | 2010-06-30 00:00:00-04:00 | 1.719333 | 2.028000 | 1.553333 | 1.588667 | 257806500 | 0.0 | 0.0 |
| 2 | 2010-07-01 00:00:00-04:00 | 1.666667 | 1.728000 | 1.351333 | 1.464000 | 123282000 | 0.0 | 0.0 |
| 3 | 2010-07-02 00:00:00-04:00 | 1.533333 | 1.540000 | 1.247333 | 1.280000 | 77097000 | 0.0 | 0.0 |
| 4 | 2010-07-06 00:00:00-04:00 | 1.333333 | 1.333333 | 1.055333 | 1.074000 | 103003500 | 0.0 | 0.0 |
tesla_url = 'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/revenue.htm'
!pip install requests==2.26.0
Collecting requests==2.26.0
Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.3/62.3 kB 9.4 MB/s eta 0:00:00
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests==2.26.0) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests==2.26.0) (2023.5.7)
Collecting charset-normalizer~=2.0.0 (from requests==2.26.0)
Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Requirement already satisfied: idna<4,>=2.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests==2.26.0) (3.4)
Installing collected packages: charset-normalizer, requests
Attempting uninstall: charset-normalizer
Found existing installation: charset-normalizer 3.1.0
Uninstalling charset-normalizer-3.1.0:
Successfully uninstalled charset-normalizer-3.1.0
Attempting uninstall: requests
Found existing installation: requests 2.29.0
Uninstalling requests-2.29.0:
Successfully uninstalled requests-2.29.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
ibm-cos-sdk-core 2.13.0 requires requests<3.0,>=2.28.1, but you have requests 2.26.0 which is incompatible.
Successfully installed charset-normalizer-2.0.12 requests-2.26.0
!mamba install bs4==4.10.0 -y
__ __ __ __
/ \ / \ / \ / \
/ \/ \/ \/ \
███████████████/ /██/ /██/ /██/ /████████████████████████
/ / \ / \ / \ / \ \____
/ / \_/ \_/ \_/ \ o \__,
/ _/ \_____/ `
|/
███╗ ███╗ █████╗ ███╗ ███╗██████╗ █████╗
████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗
██╔████╔██║███████║██╔████╔██║██████╔╝███████║
██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║
██║ ╚═╝ ██║██║ ██║██║ ╚═╝ ██║██████╔╝██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝
mamba (1.4.2) supported by @QuantStack
GitHub: https://github.com/mamba-org/mamba
Twitter: https://twitter.com/QuantStack
█████████████████████████████████████████████████████████████
Looking for: ['bs4==4.10.0']
[+] 0.0s
pkgs/main/linux-64 ━━━━━━━━╸━━━━━━━━━━━━━━━━ 0.0 B / ??.?MB @ ??.?MB/s 0.0s[+] 0.1s
pkgs/main/linux-64 ━━━━━━━━╸━━━━━━━━━━━━━━━━ 0.0 B / ??.?MB @ ??.?MB/s 0.1s
pkgs/main/noarch ━━━━━━━━━━━╸━━━━━━━━━━━━━ 0.0 B / ??.?MB @ ??.?MB/s 0.1s
pkgs/r/linux-64 ━━━━━━━━━━━━━╸━━━━━━━━━━━ 0.0 B / ??.?MB @ ??.?MB/s 0.1s
pkgs/r/noarch ━━━━━━╸━━━━━━━━━━━━━━━╸━━ 0.0 B / ??.?MB @ ??.?MB/s 0.1s[+] 0.2s
pkgs/main/linux-64 ━━━━━━━━━━╸━━━━━━━━━━━━━━ 57.4kB / ??.?MB @ 374.5kB/s 0.2s
pkgs/main/noarch ━━━━━━━━━━━━━━╸━━━━━━━━━━ 41.0kB / ??.?MB @ 265.7kB/s 0.2s
pkgs/r/linux-64 ━━━━━━━╸━━━━━━━━━━━━━━━━━ 28.7kB / ??.?MB @ 186.2kB/s 0.2s
pkgs/r/noarch ━━━━━━━━━╸━━━━━━━━━━━━━━━ 28.7kB / ??.?MB @ 186.3kB/s 0.2s[+] 0.3s
pkgs/main/linux-64 ━━━━━━━━━━━━━╸━━━━━━━━━━━ 528.4kB / ??.?MB @ 2.1MB/s 0.3s
pkgs/main/noarch ━━━━━━━━╸━━━━━━━━━━━━━━━━ 553.0kB / ??.?MB @ 2.2MB/s 0.3s
pkgs/r/linux-64 ━━━━━━━━━╸━━━━━━━━━━━━━━━ 520.2kB / ??.?MB @ 2.0MB/s 0.3s
pkgs/r/noarch ━━━━━━━━━━━╸━━━━━━━━━━━━━ 593.9kB / ??.?MB @ 2.3MB/s 0.3spkgs/main/noarch 852.1kB @ 2.7MB/s 0.3s
[+] 0.4s
pkgs/main/linux-64 ━━━━━━━━━━━━━━━╸━━━━━━━━ 1.0MB @ 2.9MB/s 0.4s
pkgs/r/linux-64 ━━━━━━━━━━━━╸━━━━━━━━━━━ 1.0MB @ 2.8MB/s 0.4s
pkgs/r/noarch ━━━━━━━━━━━━━━━━━━━━━━━━ 1.3MB @ 3.3MB/s Finalizing 0.4spkgs/r/noarch @ 3.3MB/s 0.4s
pkgs/r/linux-64 @ 3.2MB/s 0.5s
[+] 0.5s
pkgs/main/linux-64 ━━╸━━━━━━━━━━━━━━━╸━━━━━━ 1.7MB / ??.?MB @ 3.5MB/s 0.5s[+] 0.6s
pkgs/main/linux-64 ━━━━╸━━━━━━━━━━━━━━━╸━━━━ 2.2MB / ??.?MB @ 3.8MB/s 0.6s[+] 0.7s
pkgs/main/linux-64 ━━━━━━╸━━━━━━━━━━━━━━━╸━━ 2.8MB / ??.?MB @ 4.0MB/s 0.7s[+] 0.8s
pkgs/main/linux-64 ━━━━━━━━━╸━━━━━━━━━━━━━━━ 3.2MB / ??.?MB @ 4.1MB/s 0.8s[+] 0.9s
pkgs/main/linux-64 ━━━━━━━━━━━╸━━━━━━━━━━━━━ 3.7MB / ??.?MB @ 4.2MB/s 0.9s[+] 1.0s
pkgs/main/linux-64 ━━━━━━━━━━━━━━╸━━━━━━━━━━ 4.3MB / ??.?MB @ 4.3MB/s 1.0s[+] 1.1s
pkgs/main/linux-64 ━━━━━━━━━━━━━━━╸━━━━━━━━━ 4.5MB / ??.?MB @ 4.3MB/s 1.1s[+] 1.2s
pkgs/main/linux-64 ━━━━━━━━━╸━━━━━━━━━━━━━━━ 5.1MB / ??.?MB @ 4.4MB/s 1.2s[+] 1.3s
pkgs/main/linux-64 ━━━━━━━━━━━━╸━━━━━━━━━━━━ 5.6MB / ??.?MB @ 4.5MB/s 1.3s[+] 1.4s
pkgs/main/linux-64 ━━━━━━━━━━━━━━━━━━━━━━━━ 5.9MB @ 4.5MB/s Finalizing 1.4spkgs/main/linux-64 @ 4.5MB/s 1.4s
Pinned packages:
- python 3.7.*
Transaction
Prefix: /home/jupyterlab/conda/envs/python
Updating specs:
- bs4==4.10.0
- ca-certificates
- certifi
- openssl
Package Version Build Channel Size
─────────────────────────────────────────────────────────────────────────────
Install:
─────────────────────────────────────────────────────────────────────────────
+ bs4 4.10.0 hd3eb1b0_0 pkgs/main/noarch 10kB
Upgrade:
─────────────────────────────────────────────────────────────────────────────
- ca-certificates 2023.5.7 hbcca054_0 conda-forge
+ ca-certificates 2023.05.30 h06a4308_0 pkgs/main/linux-64 123kB
- openssl 1.1.1t h0b41bf4_0 conda-forge
+ openssl 1.1.1u h7f8727e_0 pkgs/main/linux-64 4MB
Downgrade:
─────────────────────────────────────────────────────────────────────────────
- beautifulsoup4 4.11.1 pyha770c72_0 conda-forge
+ beautifulsoup4 4.10.0 pyh06a4308_0 pkgs/main/noarch 87kB
Summary:
Install: 1 packages
Upgrade: 2 packages
Downgrade: 1 packages
Total download: 4MB
─────────────────────────────────────────────────────────────────────────────
[+] 0.0s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 0.0 B 0.0s
Extracting ━━━━━━━━━━━━━━━━━━━━━━━ 0 0.0s[+] 0.1s
Downloading (4) ━━━━━━━━━━━━━━━━━━━━━━━ 0.0 B beautifulsoup4 0.0s
Extracting ━━━━━━━━━━━━━━━━━━━━━━━ 0 0.0sbeautifulsoup4 86.6kB @ 599.9kB/s 0.1s
bs4 10.2kB @ 66.4kB/s 0.2s
ca-certificates 122.6kB @ 788.3kB/s 0.2s
[+] 0.2s
Downloading (1) ━━━━━━━━━━━╸━━━━━━━━━━━ 2.3MB openssl 0.1s
Extracting (3) ━━━━╸━━━━━━━━━━━━━━━╸━━ 0 beautifulsoup4 0.0sopenssl 3.9MB @ 17.9MB/s 0.2s
[+] 0.3s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━╸━━━━━━━━━━━━━━━╸━ 0 beautifulsoup4 0.1s[+] 0.4s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━╸━━━━━━━━━━━━━━━━ 0 beautifulsoup4 0.2s[+] 0.5s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━╸━━━━━━━━━━━━━━━ 0 beautifulsoup4 0.3s[+] 0.6s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━╸━━━━━━━━━━━━━━ 0 bs4 0.4s[+] 0.7s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━╸━━━━━━━━━━━━━ 0 bs4 0.5s[+] 0.8s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━╸━━━━━━━━━━━━ 0 bs4 0.6s[+] 0.9s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━╸━━━━━━━━━━━ 0 bs4 0.7s[+] 1.0s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━━━╸━━━━━━━━━ 0 ca-certificates 0.8s[+] 1.1s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━╸━━━━━━━━━━━━━━ 0 ca-certificates 0.9s[+] 1.2s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━╸━━━━━━━━━━━━━ 0 ca-certificates 1.0s[+] 1.3s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━╸━━━━━━━━━━━━ 0 ca-certificates 1.1s[+] 1.4s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━╸━━━━━━━━━━━ 0 openssl 1.2s[+] 1.5s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━━╸━━━━━━━━━━ 0 openssl 1.3s[+] 1.6s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━━━╸━━━━━━━━━ 0 openssl 1.4s[+] 1.7s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━━━━╸━━━━━━━━ 0 openssl 1.5s[+] 1.8s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ━━━━━━━━━━━━━━━╸━━━━━━━ 0 beautifulsoup4 1.6s[+] 1.9s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (4) ╸━━━━━━━━━━━━━━━╸━━━━━━ 0 beautifulsoup4 1.7s[+] 2.0s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (3) ━━━━╸━━━━━━━━━━━━━━━━━━ 1 beautifulsoup4 1.8s[+] 2.1s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting (3) ━━━━╸━━━━━━━━━━━━━━━━━━ 1 beautifulsoup4 1.9s[+] 2.2s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 4.1MB 0.2s
Extracting ━━━━━━━━━━━━━━━━━━━━━━━ 4 2.0s
Downloading and Extracting Packages
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
!mamba install html5lib==1.1 -y
!pip install lxml==4.6.4
__ __ __ __
/ \ / \ / \ / \
/ \/ \/ \/ \
███████████████/ /██/ /██/ /██/ /████████████████████████
/ / \ / \ / \ / \ \____
/ / \_/ \_/ \_/ \ o \__,
/ _/ \_____/ `
|/
███╗ ███╗ █████╗ ███╗ ███╗██████╗ █████╗
████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗
██╔████╔██║███████║██╔████╔██║██████╔╝███████║
██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║
██║ ╚═╝ ██║██║ ██║██║ ╚═╝ ██║██████╔╝██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝
mamba (1.4.2) supported by @QuantStack
GitHub: https://github.com/mamba-org/mamba
Twitter: https://twitter.com/QuantStack
█████████████████████████████████████████████████████████████
Looking for: ['html5lib==1.1']
pkgs/main/linux-64 Using cache
pkgs/main/noarch Using cache
pkgs/r/linux-64 Using cache
pkgs/r/noarch Using cache
Pinned packages:
- python 3.7.*
Transaction
Prefix: /home/jupyterlab/conda/envs/python
Updating specs:
- html5lib==1.1
- ca-certificates
- certifi
- openssl
Package Version Build Channel Size
──────────────────────────────────────────────────────────────────────
Install:
──────────────────────────────────────────────────────────────────────
+ html5lib 1.1 pyhd3eb1b0_0 pkgs/main/noarch 93kB
+ webencodings 0.5.1 py37_1 pkgs/main/linux-64 20kB
Summary:
Install: 2 packages
Total download: 113kB
──────────────────────────────────────────────────────────────────────
[+] 0.0s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 0.0 B 0.0s
Extracting ━━━━━━━━━━━━━━━━━━━━━━━ 0 0.0s[+] 0.1s
Downloading (2) ━━━━━━━━━━━━━━━━━━━━━━━ 0.0 B html5lib 0.0s
Extracting ━━━━━━━━━━━━━━━━━━━━━━━ 0 0.0swebencodings 19.6kB @ 141.7kB/s 0.1s
html5lib 93.0kB @ 644.8kB/s 0.1s
[+] 0.2s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━━━╸━━━━━━━━━━━ 0 html5lib 0.0s[+] 0.3s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━━━━━╸━━━━━━━━━ 0 html5lib 0.1s[+] 0.4s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━╸━━━━━━━━━━━━━━ 0 html5lib 0.2s[+] 0.5s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━╸━━━━━━━━━━━━━ 0 html5lib 0.3s[+] 0.6s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━━╸━━━━━━━━━━━━ 0 webencodings 0.4s[+] 0.7s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━━━╸━━━━━━━━━━━ 0 webencodings 0.5s[+] 0.8s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━━━━╸━━━━━━━━━━ 0 webencodings 0.6s[+] 0.9s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (2) ━━━━━━━━━━━━━╸━━━━━━━━━ 0 webencodings 0.7s[+] 1.0s
Downloading ━━━━━━━━━━━━━━━━━━━━━━━ 112.6kB 0.1s
Extracting (1) ━━━━━━━━━━╸━━━━━━━━━━━━ 1 webencodings 0.8s
Downloading and Extracting Packages
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Collecting lxml==4.6.4
Downloading lxml-4.6.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.3/6.3 MB 80.7 MB/s eta 0:00:00:00:0100:01
Installing collected packages: lxml
Attempting uninstall: lxml
Found existing installation: lxml 4.9.2
Uninstalling lxml-4.9.2:
Successfully uninstalled lxml-4.9.2
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
yfinance 0.2.4 requires beautifulsoup4>=4.11.1, but you have beautifulsoup4 4.10.0 which is incompatible.
yfinance 0.2.4 requires lxml>=4.9.1, but you have lxml 4.6.4 which is incompatible.
Successfully installed lxml-4.6.4
import requests
from bs4 import BeautifulSoup
r=requests.get(tesla_url).text
soup = BeautifulSoup(r, 'html5lib')
Tesla_revenue = pd.DataFrame(columns = ["Date", "Revenue"])
table=soup.find_all("tbody")[1]
for row in table.find_all('tr'):
col = row.find_all('td')
if (col != []):
date = col[0].text
revenue = col[1].text
Tesla_revenue = Tesla_revenue.append({"Date":date, "Revenue":revenue}, ignore_index=True)
Tesla_revenue["Revenue"] = Tesla_revenue['Revenue'].str.replace(',|\$',"")
/home/jupyterlab/conda/envs/python/lib/python3.7/site-packages/ipykernel_launcher.py:1: FutureWarning: The default value of regex will change from True to False in a future version. """Entry point for launching an IPython kernel.
Tesla_revenue
| Date | Revenue | |
|---|---|---|
| 0 | 2022-09-30 | 21454 |
| 1 | 2022-06-30 | 16934 |
| 2 | 2022-03-31 | 18756 |
| 3 | 2021-12-31 | 17719 |
| 4 | 2021-09-30 | 13757 |
| 5 | 2021-06-30 | 11958 |
| 6 | 2021-03-31 | 10389 |
| 7 | 2020-12-31 | 10744 |
| 8 | 2020-09-30 | 8771 |
| 9 | 2020-06-30 | 6036 |
| 10 | 2020-03-31 | 5985 |
| 11 | 2019-12-31 | 7384 |
| 12 | 2019-09-30 | 6303 |
| 13 | 2019-06-30 | 6350 |
| 14 | 2019-03-31 | 4541 |
| 15 | 2018-12-31 | 7226 |
| 16 | 2018-09-30 | 6824 |
| 17 | 2018-06-30 | 4002 |
| 18 | 2018-03-31 | 3409 |
| 19 | 2017-12-31 | 3288 |
| 20 | 2017-09-30 | 2985 |
| 21 | 2017-06-30 | 2790 |
| 22 | 2017-03-31 | 2696 |
| 23 | 2016-12-31 | 2285 |
| 24 | 2016-09-30 | 2298 |
| 25 | 2016-06-30 | 1270 |
| 26 | 2016-03-31 | 1147 |
| 27 | 2015-12-31 | 1214 |
| 28 | 2015-09-30 | 937 |
| 29 | 2015-06-30 | 955 |
| 30 | 2015-03-31 | 940 |
| 31 | 2014-12-31 | 957 |
| 32 | 2014-09-30 | 852 |
| 33 | 2014-06-30 | 769 |
| 34 | 2014-03-31 | 621 |
| 35 | 2013-12-31 | 615 |
| 36 | 2013-09-30 | 431 |
| 37 | 2013-06-30 | 405 |
| 38 | 2013-03-31 | 562 |
| 39 | 2012-12-31 | 306 |
| 40 | 2012-09-30 | 50 |
| 41 | 2012-06-30 | 27 |
| 42 | 2012-03-31 | 30 |
| 43 | 2011-12-31 | 39 |
| 44 | 2011-09-30 | 58 |
| 45 | 2011-06-30 | 58 |
| 46 | 2011-03-31 | 49 |
| 47 | 2010-12-31 | 36 |
| 48 | 2010-09-30 | 31 |
| 49 | 2010-06-30 | 28 |
| 50 | 2010-03-31 | 21 |
| 51 | 2009-12-31 | |
| 52 | 2009-09-30 | 46 |
| 53 | 2009-06-30 | 27 |
Tesla_revenue.dropna(inplace=True)
Tesla_revenue = Tesla_revenue[Tesla_revenue['Revenue'] != ""]
Tesla_revenue.tail()
| Date | Revenue | |
|---|---|---|
| 48 | 2010-09-30 | 31 |
| 49 | 2010-06-30 | 28 |
| 50 | 2010-03-31 | 21 |
| 52 | 2009-09-30 | 46 |
| 53 | 2009-06-30 | 27 |
Gamestop = yf.Ticker("GME")
Gamestop_data = Gamestop.history(period="max")
Gamestop_data.reset_index(inplace=True)
Gme_data = pd.DataFrame(Gamestop_data)
Gme_data.head()
| Date | Open | High | Low | Close | Volume | Dividends | Stock Splits | |
|---|---|---|---|---|---|---|---|---|
| 0 | 2002-02-13 00:00:00-05:00 | 1.620128 | 1.693350 | 1.603296 | 1.691667 | 76216000 | 0.0 | 0.0 |
| 1 | 2002-02-14 00:00:00-05:00 | 1.712707 | 1.716074 | 1.670626 | 1.683250 | 11021600 | 0.0 | 0.0 |
| 2 | 2002-02-15 00:00:00-05:00 | 1.683251 | 1.687459 | 1.658002 | 1.674834 | 8389600 | 0.0 | 0.0 |
| 3 | 2002-02-19 00:00:00-05:00 | 1.666418 | 1.666418 | 1.578047 | 1.607504 | 7410400 | 0.0 | 0.0 |
| 4 | 2002-02-20 00:00:00-05:00 | 1.615920 | 1.662210 | 1.603296 | 1.662210 | 6892800 | 0.0 | 0.0 |
Html_data = ' https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/stock.html'
data = requests.get(Html_data).text
soup2 = BeautifulSoup(data, 'html5lib')
Gme_revenue = pd.DataFrame(columns = ["Date", "Revenue"])
table=soup2.find_all("tbody")[1]
for row in table.find_all('tr'):
col = row.find_all('td')
if (col != []):
date = col[0].text
revenue = col[1].text
Gme_revenue = Gme_revenue.append({"Date":date, "Revenue":revenue}, ignore_index=True)
Gme_revenue["Revenue"] = Gme_revenue['Revenue'].str.replace(',|\$',"")
/home/jupyterlab/conda/envs/python/lib/python3.7/site-packages/ipykernel_launcher.py:1: FutureWarning: The default value of regex will change from True to False in a future version. """Entry point for launching an IPython kernel.
Gme_revenue.tail()
| Date | Revenue | |
|---|---|---|
| 57 | 2006-01-31 | 1667 |
| 58 | 2005-10-31 | 534 |
| 59 | 2005-07-31 | 416 |
| 60 | 2005-04-30 | 475 |
| 61 | 2005-01-31 | 709 |
!pip install plotly==5.3.1
Collecting plotly==5.3.1
Downloading plotly-5.3.1-py2.py3-none-any.whl (23.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.9/23.9 MB 41.8 MB/s eta 0:00:0000:0100:01
Requirement already satisfied: tenacity>=6.2.0 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from plotly==5.3.1) (8.2.2)
Requirement already satisfied: six in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from plotly==5.3.1) (1.16.0)
Installing collected packages: plotly
Attempting uninstall: plotly
Found existing installation: plotly 5.14.1
Uninstalling plotly-5.14.1:
Successfully uninstalled plotly-5.14.1
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
dash 2.9.3 requires dash-core-components==2.0.0, which is not installed.
dash 2.9.3 requires dash-html-components==2.0.0, which is not installed.
dash 2.9.3 requires dash-table==5.0.0, which is not installed.
Successfully installed plotly-5.3.1
def make_graph(stock_data, revenue_data, stock):
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("Historical Share Price", "Historical Revenue"), vertical_spacing = .3)
stock_data_specific = stock_data[stock_data.Date <= '2021--06-14']
revenue_data_specific = revenue_data[revenue_data.Date <= '2021-04-30']
fig.add_trace(go.Scatter(x=pd.to_datetime(stock_data_specific.Date, infer_datetime_format=True), y=stock_data_specific.Close.astype("float"), name="Share Price"), row=1, col=1)
fig.add_trace(go.Scatter(x=pd.to_datetime(revenue_data_specific.Date, infer_datetime_format=True), y=revenue_data_specific.Revenue.astype("float"), name="Revenue"), row=2, col=1)
fig.update_xaxes(title_text="Date", row=1, col=1)
fig.update_xaxes(title_text="Date", row=2, col=1)
fig.update_yaxes(title_text="Price ($US)", row=1, col=1)
fig.update_yaxes(title_text="Revenue ($US Millions)", row=2, col=1)
fig.update_layout(showlegend=False,
height=900,
title=stock,
xaxis_rangeslider_visible=True)
fig.show()
import plotly.graph_objects as go
from plotly.subplots import make_subplots
make_graph(tesla_data, Tesla_revenue, 'tesla')
make_graph(Gme_data, Gme_revenue, 'GameStop')